package com.huahua.graduateschoolspringboot.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.huahua.graduateschoolspringboot.enums.DeviceTypeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @author LoveHuaHua
 * @date 2023年05月07日 10:44
 * @description believe in yourself
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class BusDeviceCommandHandler implements IDeviceCommandHandler {

    private final ObjectMapper objectMapper;

    /**
     * 是否支持
     *
     * @param deviceType 设备类型
     * @return boolean
     */
    @Override
    public boolean support(String deviceType) {
        return DeviceTypeEnum.BUS.getPackageIdentification().equals(deviceType);
    }

    /**
     * 执行
     *
     * @param objectNode 对象节点
     */
    @Override
    public void execute(ObjectNode objectNode) throws JsonProcessingException {
        //上传的经纬度
        objectNode.put("latitude", objectNode.get("latitude").asText());
    }
}
